package org.yoki.edu.bg.radius.web.api.impl.rest;

import com.yunzhitx.cloud.common.model.InvokeResult;
import com.yunzhitx.cloud.common.model.PageResult;

import java.util.List;

/**
 * @author kissy
 * @Description: TODO
 * @date 2017/11/10 下午2:55
 */
public class BaseController {

    public Integer getLoginId(){
//        Object s =  SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        if(null!=s && s instanceof JwtUser){
//            JwtUser user = (JwtUser) s;
//            return Integer.valueOf(user.getId());
//        }else{
//            throw new AccessDeniedException("用户信息有误！");
//        }
        return 0 ;
    }

    public InvokeResult buildInvokeResult(Object vo){
        InvokeResult invokeResult;
        if (null == vo) {
            invokeResult = InvokeResult.passNoData();
        } else {
            invokeResult = InvokeResult.ok(vo);
        }
        return invokeResult;
    }

    public InvokeResult buildListInvokeResult(List list){
        InvokeResult invokeResult;
        if (null == list || list.size() <= 0) {
            invokeResult = InvokeResult.passNoData();
        } else {
            invokeResult = InvokeResult.ok(list);
        }
        return invokeResult;
    }

    public InvokeResult buildPageInvokeResult(PageResult page){
        InvokeResult invokeResult;
        if (null == page || null == page.getPageData() || page.getPageData().size() <= 0) {
            invokeResult = InvokeResult.passNoData();
        } else {
            invokeResult = InvokeResult.ok(page);
        }
        return invokeResult;
    }

}